package com.boluo.web.controller.businessManagement;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.boluo.businessManagement.dto.BusMentContractDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.boluo.common.annotation.Log;
import com.boluo.common.core.controller.BaseController;
import com.boluo.common.core.domain.AjaxResult;
import com.boluo.common.enums.BusinessType;
import com.boluo.businessManagement.domain.BusMentContract;
import com.boluo.businessManagement.service.IBusMentContractService;
import com.boluo.common.utils.poi.ExcelUtil;
import com.boluo.common.core.page.TableDataInfo;

/**
 * 合同信息Controller
 * 
 * @author xlk
 * @date 2023-05-02
 */
@RestController
@RequestMapping("/businessManagement/contract")
public class BusMentContractController extends BaseController
{
    @Autowired
    private IBusMentContractService busMentContractService;

    /**
     * 查询合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('businessManagement:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusMentContractDTO busMentContractDTO)
    {
        startPage();
        List<BusMentContract> list = busMentContractService.selectBusMentContractList(busMentContractDTO);
        return getDataTable(list);
    }

//    /**
//     * 导出合同信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('businessManagement:contract:export')")
//    @Log(title = "合同信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, BusMentContract busMentContract)
//    {
//        List<BusMentContract> list = busMentContractService.selectBusMentContractList(busMentContract);
//        ExcelUtil<BusMentContract> util = new ExcelUtil<BusMentContract>(BusMentContract.class);
//        util.exportExcel(response, list, "合同信息数据");
//    }

    /**
     * 获取合同信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('businessManagement:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busMentContractService.selectBusMentContractById(id));
    }

    /**
     * 新增合同信息
     */
    @PreAuthorize("@ss.hasPermi('businessManagement:contract:add')")
    @Log(title = "合同信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusMentContract busMentContract)
    {
        return toAjax(busMentContractService.insertBusMentContract(busMentContract));
    }

    /**
     * 修改合同信息
     */
    @PreAuthorize("@ss.hasPermi('businessManagement:contract:edit')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusMentContract busMentContract)
    {
        return toAjax(busMentContractService.updateBusMentContract(busMentContract));
    }

    /**
     * 删除合同信息
     */
    @PreAuthorize("@ss.hasPermi('businessManagement:contract:remove')")
    @Log(title = "合同信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busMentContractService.deleteBusMentContractByIds(ids));
    }

    /**
     * 审核通过
     */
    @Log(title = "审核通过", businessType = BusinessType.UPDATE)
    @PutMapping("/auditYes/{id}")
    public AjaxResult auditYes(@PathVariable Long id)
    {
        return toAjax(busMentContractService.auditYes(id));
    }

    /**
     * 审核不通过
     */
    @Log(title = "审核不通过", businessType = BusinessType.UPDATE)
    @PutMapping("/auditNo/{id}")
    public AjaxResult auditNo(@PathVariable Long id)
    {
        return toAjax(busMentContractService.auditNo(id));
    }

    /**
     * 确认盖章
     */
    @Log(title = "确认盖章", businessType = BusinessType.UPDATE)
    @PutMapping("/sealYes/{id}")
    public AjaxResult sealYes(@PathVariable Long id)
    {
        return toAjax(busMentContractService.sealYes(id));
    }

    /**
     * 作废合同
     */
    @Log(title = "作废合同", businessType = BusinessType.UPDATE)
    @PutMapping("/InvalidYes/{id}")
    public AjaxResult InvalidYes(@PathVariable Long id)
    {
        return toAjax(busMentContractService.InvalidYes(id));
    }

    /**
     * 下载合同附件
     */
    @Log(title = "下载合同附件", businessType = BusinessType.UPDATE)
    @GetMapping("/downloadAnnex/{id}")
    public AjaxResult downloadAnnex(@PathVariable Long id) throws IOException {
        busMentContractService.downloadAnnex(id);
        return AjaxResult.success("下载成功");
    }
}
